import { defineStore } from "pinia";
import { ref } from 'vue'
import { getEqPoint, getSubordinateEquipments } from '@/api/equipment';
export const useLocationEq = defineStore('useLocationEq', () => {
    const eqData = ref()
    const setEqData = async params => {
        let pointres: [] = (await getEqPoint()).data
        let res: any = await getSubordinateEquipments(params);
        if (pointres.length > 0) {
            pointres.forEach((item: any) => {
                res.data.forEach(element => {
                    if (item.equipmentLocationCode == element.equipmentLocationCode) {
                        Object.assign(element, { select: false })
                    }
                });
            })

        }
        console.log(res.data);

        eqData.value = res.data

    };
    const setEqDataSelect = (code) => {
        // console.log('现在的数据是------------------', eqData.value);
        console.log(eqData.value, '123456index');
        if (eqData.value) {
            const index = eqData.value.findIndex((item) => {
                return item.equipmentLocationCode == code
            })


            if (index > -1) {
                eqData.value[index].select = true
            }
        } else {
            return
        }


    }
    return {
        eqData,
        setEqData,
        setEqDataSelect
    }
})  